package com.ly.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ly.entity.Message;
import com.ly.pojo.dto.MessageDTO;
import com.ly.pojo.vo.MessageVO;
import com.ly.service.MessageService;
import com.ly.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 黑渊白花
 * @ClassName MessageController
 * @date : 2025/2/27 13:41
 * @Description
 */
@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/message")
@Slf4j
public class MessageController {
    @Autowired
    private MessageService messageService;
    @GetMapping("/list")
    public Result list(){
        List<Message> list = messageService.list();
        return Result.success(list);
    }

    @GetMapping("/page")
    public Object page( MessageDTO messageDTO){
        log.info("{}",messageDTO);
        IPage<MessageVO> page=null;
        page= messageService.getAllPage(messageDTO);
        return Result.success(page);
    }

    @GetMapping("/getByStuId/{stuId}")
    public Result getByStuId( @PathVariable Integer stuId){
        return messageService.getByStuId(stuId);
    }

    @PutMapping("/reply")
    public Result reply(@RequestBody Message message){
        messageService.reply(message);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Message message){
        messageService.updateById(message);
        return Result.success();
    }

    @PostMapping("/save")
    public Result save(@RequestBody Message message){
        messageService.save(message);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        messageService.removeById(id);
        return Result.success("删除成功");
    }


}
